var urlSplit = window.location.href.split("/");
var common = {
    prize: {},
    // urlPage: 'http://127.0.0.1:5500/static',
    // urlPage: window.location.protocol + "//" + window.location.host + "/" + urlSplit[3] + "/" + urlSplit[4],
    // url: 'http://192.168.14.187:8090',
    url: window.location.protocol + "//" + window.location.host + "/" + urlSplit[3] + "/" + urlSplit[4],
    notice1: "目前参与人数较多，请稍后再试！",
    skipUrl: "https://live.polyv.cn/watch/239952",
};



$.ajax({
    type: 'get',
    url: common.url + "/external/getServerConfig",
    dataType: "json",
    // url: window.location.protocol + "//" + window.location.host + "/" + urlSplit[3] + "/" + urlSplit[4] + "/external/getServerConfig",
    success: function (data) {

        var index = -1;

        if (!data.success) {
            return;
        }

        var resp = JSON.parse(data.content.serverConfig);

        console.log(resp);

        var tempKeys = [];

        for (var i = 0; i < resp.groupList.length; i++) {
            tempKeys.push(resp.groupList[i]["group_id"]);
        }
        
        for (var j = 0; j < tempKeys.length; j++) {
            var temp = resp[tempKeys[j]];
            var tempData = {};
            var tempCode = "";
            for (var k = 0; k < temp.length; k++) {
                if (temp[k]["type"] == "picture") {

                    tempData["url"] = temp[k]["url"];
                    
                    if (temp[k]["key"] === "prizeBackground") {
                        $(".game li").css("background","url(" + temp[k]["url"] + ")");
                        $(".game li").css("backgroundSize","cover");
                    }
                    
                }
                if (temp[k]["key"] == "awardsName") {
                    tempData["title"] = temp[k]["value"];
                }
                if (temp[k]["key"] == "prizeType") {
                    tempData["status"] = temp[k]["value"];
                }
                if (temp[k]["key"] == "awardsCode") {
                    tempData["awardsCode"] = temp[k]["value"];
                    tempCode = temp[k]["value"];
                    index++;  //有奖品编码再加position
                    tempData["position"] = index;
                }
                
            }
        
            common.prize[tempCode] = tempData;

            common["deploycolId"] = data.content.deploycolId;
        
            $("#" + tempData["position"]).attr("src", tempData["url"]);

        }
        console.log(common);
    },
});